package com.TinyBBS.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.TinyBBS.bean.Game;
import com.TinyBBS.bean.Review;
import com.TinyBBS.model.GameModel;
import com.TinyBBS.model.ReviewModel;

/**
 * Servlet implementation class GameDetail
 */
public class GameDetail extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String gameid = request.getParameter("id");
		String uri = "/views/gameDetail.jsp";
		String error = "";
		GameModel gameM = new GameModel();
		ReviewModel reviewM = new ReviewModel();
		Game game = new Game();
		game = gameM.getGameById(gameid);
		List<Review> reviewList = reviewM.getReviewListByGameId(game.getId());
		if (game == null) {
			uri = "/views/404Error.jsp";
		}
		request.setAttribute("error", error);
		request.setAttribute("gameContent", game);
		request.setAttribute("reviewList", reviewList);
		request.getRequestDispatcher(uri).forward(request, response);

	}
}
